#define _CRT_SECURE_NO_WARNINGS 1
#include<cstdio>
struct pol
{
	int ex;
	double coe;
	
}arr[30],arr1[1001];

int max(int x, int y)
{
	if (x > y) return x;
	else return y;
}

int main()
{
	int i, j, k ,m, K1 ,K2,count;
	i = j = K1 = K2 = k = m = count = 0;
	scanf("%d", &K1);
	while (K1 > 0)
	{
		scanf("%d %lf", &arr[k].ex, &arr[k].coe);
		
		K1--;
		k++;
	}
	
	scanf("%d", &K2);
	while (K2 > 0)
	{
		scanf("%d %lf", &arr[k].ex, &arr[k].coe);
		
		K2--;
		k++;
	}
	k -= 1;
	for (i; i < k+1; i++)
	{
		arr1[arr[i].ex].coe += (arr[i].coe);
		m = max(m, arr[i].ex);
	}
	for (j; j <= m; j++)
	{
		if (arr1[j].coe != 0)
		{
			count++;
		}
	}
	printf("%d", count);
	for (int n=m; n >=0; n--)
	{
		if (arr1[n].coe != 0)
		{
			printf(" %d ", n);
			printf("%.1lf", arr1[n].coe);
		}
	}
	



	
	return 0;
}